import request from '@/LC/request/index';
import { baseUrl } from '@/LC/config';
import LC from '..';

export default {
	// 系统初始化
	init: (templateId) =>
		request({
			url: '/api/baseConfig',

			custom: {
				showError: false,
				showLoading: false,
			},
		}),
	lang: () =>
		request({
			url: '/api/language',

			custom: {
				showError: false,
				showLoading: false,
			},
		}),
	forex: () =>
		request({
			url: '/api/forex',
	
			custom: {
				showError: false,
				showLoading: false,
			},
		}),	
	page: (code) =>
		request({
			url: '/api/index/text',
			data:{code},
			custom: {
				
				showLoading: true,
			},
		}),
	commonProblem: (code) =>
		request({
			url: '/api/commonProblem',
	
			custom: {
				
				showLoading: true,
			},
		}),	
	//上传
	upload: (file, group = 'ugc', callback) => {
		const token = uni.getStorageSync('token');
		uni.showLoading({
			title: LC.$t('scz'),
		});
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: baseUrl + '/api/common/upload',
				filePath: file,
				name: 'file',
				formData: {
					group,
				},
				header: {
					Accept: 'text/json',
					// Authorization: token,
					token: token
				},
				success: (uploadFileRes) => {
					let result = JSON.parse(uploadFileRes.data);
					if (result.code === 0) {
						uni.showToast({
							icon: 'none',
							title: result.msg,
						});
					} else {
						return resolve(result.data);
					}
				},
				fail: (error) => {
					console.log('上传失败：', error);
					return resolve(false);
				},
				complete: () => {
					uni.hideLoading();
				},
			});
		});
	},
};